package common

import "fmt"

const (
	UICodeOk          = 0 //请求成功
	UICodeAuth        = 2 //未登录
	UICodeErr         = 3 //请求失败
	UICodeErrs        = 4 //请求失败 args
	UICodeErrParam    = 5 //参数错误
	UICodeErrNotFound = 6 //未找到数据
	UICodePermission  = 7 //无权限

	// install
	UICodeInstallWait = 100 //等待数据库

	// sys 10000+
	UICodeSysNoSetting = 10001
	// login 20000+
	UICodeLoginNoSetOAauth = 20001
)

var msgs map[string]string

func GetUIMsg(lc string, code int, args ...interface{}) string {
	if msgs == nil {
		msgs = make(map[string]string)
		initZHUiMsg()
	}
	fs := msgs[fmt.Sprintf("%s:%d", lc, code)]
	if len(args) > 0 {
		return fmt.Sprintf(fs, args...)
	}
	return fs
}

func setUIMsg(lc string, code int, msgfmt string) {
	msgs[fmt.Sprintf("%s:%d", lc, code)] = msgfmt
}
func initZHUiMsg() {
	lc := "zh"
	setUIMsg(lc, UICodeOk, "请求成功")
	setUIMsg(lc, UICodeAuth, "无权限")
	setUIMsg(lc, UICodeErr, "请求失败")
	setUIMsg(lc, UICodeErrs, "请求失败:%v")
	setUIMsg(lc, UICodeErrParam, "参数错误")
	setUIMsg(lc, UICodeErrNotFound, "尚未找到任何内容")

	setUIMsg(lc, UICodeLoginNoSetOAauth, "未配置oauth信息")
}
